﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DocumentFormat.OpenXml;
using ecdl.demo.model.expression;
using DocumentFormat.OpenXml.Wordprocessing;

namespace ecdl.demo.model.expression {
    public class ParagraphContainsDateFieldExpression : WordExpression {
        private static readonly string POS_CAUSE = "Datumsfeld konnte gefunden werden.";
        private static readonly string NEG_CAUSE = "Datumsfeld konnte nicht gefunden werden";

        protected override ExpressionState Evaluate(IEnumerable<OpenXmlElement> contextElements) {
            foreach (var element in contextElements) {
                IEnumerable<FieldCode> fields = element.Descendants<FieldCode>();
                foreach (var field in fields) {
                    if (field.Text.Contains("TIME")) {
                        return Success(POS_CAUSE, NEG_CAUSE);
                    }
                }
            }
            return Fail(NEG_CAUSE, POS_CAUSE);
        }
    }

    public class ParagraphContainsDateFieldExpressionDTO : ExpressionDTO {

        public ParagraphContainsDateFieldExpressionDTO() :base(typeof(ParagraphContainsDateFieldExpression)) {
        }

    }
}
